package com.yitongmao.common;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import java.util.Timer;
import java.util.TimerTask;


public class SaveTempDataTempService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
//        new Thread(new Runnable() {
//            public void run() {
////                Log.d("LongRunningService", "executed at" + new AppDateCommon().toString());
//            }
//        }).start();

//        AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
//        int anHour = 60 * 60 * 1000;
//        int anMinite = 5000;
//        long triggerAtTime = SystemClock.elapsedRealtime() + anMinite;
//        Intent i = new Intent(this, NewEditPublishActivity.SaveLocalArticalDataTempReceiver.class);
//        i.setAction("SAVE_TO_ARTICAL_DATA");//自定义Action
//        PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
//        manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //定时器每隔10秒发送一次广播
        new Timer().scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                Intent timeIntent = new Intent();
                timeIntent.setAction("SAVE_TO_ARTICAL_DATA");//自定义Action
                sendBroadcast(timeIntent); //发送广播
            }
        }, 0, 10000);
    }
}
